package com.meyoung.actions;

import com.meyoung.driver.SeleniumDriver;
import com.meyoung.find.WebElementUtile;
import com.meyoung.logger.LoggerControler;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

import javax.swing.plaf.basic.BasicSliderUI;
import java.util.ArrayList;
import java.util.List;

public class Action1 {
//    public static void get(By by,String url){
////        if (url.startsWith("http")) {
////            String url2 = "http://" + url;
////            driver.get(url2);
////        }else {
////            driver.get(url);
////        }
//    }
    final static LoggerControler log = LoggerControler.getlogger(Action1.class);
    //打开网站
    public static void get(WebDriver driver,String url){
        driver.get(url);
        log.info("打开网站"+url);
    }
    //点击方法
    public static void click(By by){
        WebElementUtile.findElement(by).click();
        log.info("点击："+by);
    }
    //文本框输入方法
    public static void sendText(By by,String text){
        WebElement element =WebElementUtile.findElement(by);
        element.clear();
        element.sendKeys(text);
        log.info("在文本框为"+by+"输入了"+text);
    }
    //获取文本
    public static String getText(By by){
        String text = WebElementUtile.findElement(by).getText();
        return text;
    }
    //获取多个文本值
    public static ArrayList getTexts(By by){
        ArrayList arrayList = new ArrayList();
        List<WebElement> list = WebElementUtile.findElements(by);
        for (int i = 0; i < list.size();i++){
            String text =list.get(i).getText();
            arrayList.add(text);
        }
        return arrayList;
    }
    //双击
    public static void doubleClick(WebDriver driver,By by){
        Actions actions = new Actions(driver);
        WebElement element = WebElementUtile.findElement(by);
        actions.doubleClick(element).perform();
    }
}
